require "Equip"
require "HeroData"

loginURL = "http://user.blessjoy.com/login/login"
--loginURL = "http://login.chaogu001.com/login/login"

NetworkRequest = {}
NetworkRequest.makeChecksum = function(val)
  local randomStr = "F959sLW9rEKo0hgB7MWq4.EM9fAWFeRG"
  local timeStr = string.format("%d000", os.time())
  local sum = 0
  for i=1,string.len(randomStr) do
    local b = string.byte(randomStr, i)
    sum = sum+b
  end
  for i=1,string.len(val) do
    local b = string.byte(val, i)
    sum = sum+b+1
  end
  for i=1,string.len(timeStr) do
    local b = string.byte(timeStr, i)
    sum = sum+b
  end
  local res = string.format("%s-%s-%d", randomStr, timeStr, sum%256)  
  print("NetworkRequest.makeChecksum", randomStr, timeStr, sum%256)
  return res
end

NetworkRequest.syncData = function(res)
  if res.sync~=nil then
    Player.reload()
    for k,v in pairs(res.sync) do
      UserData.userinfo.host[k] = v
    end
  end
  if res.quests~=nil then
    UserData.userinfo.quests = res.quests 
  end
  if res.curQuests~=nil then
    UserData.userinfo.curQuests = res.curQuests
  end
  if res.serverTime~=nil then
    TimeManager.deltaTime = res.serverTime - os.time()
  end
end
--print(NetworkRequest.makeChecksum('{"bid":1001}'))
--%s?openid=0000000000000000000000005B168614&check=%s&openkey=A76D7BCF866939B8121DDE9B5C9E9CD9&pf=pengyou&pfkey=c6c150ba2bd86315549585da7c3dbb49&qz_ver=6&appcanvas=1&via=PY.TOPBAR.SEARCH


NetworkRequest.login = function(name, password, callback, target)
  --local url = "login.blessjoy.com/login/login"
  local url = "http://user.blessjoy.com/login/login"
  --local url = "http://login.chaogu001.com/login/login"
  CCHttpClient:request(url, callback, string.format('{"name":"%s", "password":"%s"}', name, password), nil, target)
end

--[[
function onLogin(data)
  print(data)
  local res = cjson.decode(data)
  cayuan_session_key = res["cayuan_session_key"]
  cayuan_user = res["cayuan_user"]  
  --urlTpl = string.format("http://cayuan.war.alonew.com/%%s?check=%%s&cayuan_user=%s&cayuan_session_key=%s", cayuan_user, cayuan_session_key)
  urlTpl = string.format("http://cayuan.war.blessjoy.com/%%s?check=%%s&cayuan_user=%s&cayuan_session_key=%s", cayuan_user, cayuan_session_key)
  print(urlTpl)
  NetworkRequest.getUserInfo()
  --NetworkRequest.jingJiChang()
end
]]
NetworkRequest.register = function(name, password, callback, target)
  --local url = "login.blessjoy.com/login/register"
  local url = "user.blessjoy.com/login/register"
  --local url = "http://login.chaogu001.com/login/register"
  CCHttpClient:request(url, callback, string.format('{"name":"%s", "password":"%s"}', name, password), nil, target)
end
NetworkRequest.uniqueCheck = function(name, callback, target)
  local postdata = string.format("name=%s", name)
  local checksum = NetworkRequest.makeChecksum(postdata)
  --local uri = "/login/uniqueCheck"
  local url = "login.blessjoy.com/login/uniqueCheck"
  --local url = "http://login.chaogu001.com/login/uniqueCheck"
  local header = CCArray:create()
  header:addObject(CCString:create("Content-Type:application/x-www-form-urlencoded"))
  CCHttpClient:request(url, callback, postdata, header, target)
end

--http://app18894.qzoneapp.com/game/newAthletics/login?queryId=qid5&postKey=aabbccdd&check=D7g,R3,oH0aDU6nNZgLbv31muhnlkwNI-1365085226849-29&openkey=7BE73DFA5880DB5650BCAA3749346046&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=0f2d922fd279602acf37512b572b5ddd&onlysign=
--urlTpl="http://app18894.qzoneapp.com/%s?openid=0000000000000000000000005B1686144&check=%s&openkey=EBC0E61B443A2F898B04552AB982DB33&pf=pengyou&pfkey=adbab8bc708ebbc5d460c58b8ee65e4b&qz_ver=6&appcanvas=1&via=PY.MYAPP"
--urlTpl="http://app18894.qzoneapp.com/%s?openid=0000000000000000000000005B168614&check=%s&openkey=B407514A6CEE2F2930DC2D1B02FFA799&pf=pengyou&pfkey=97d5ddc49671fdcb860af2ff4670c01a&qz_ver=6&appcanvas=1&via=PY.MYAPP"
NetworkRequest.getUserInfo = function(callback, target)
  print("NetworkRequest.getUserInfo")
  local checksum = NetworkRequest.makeChecksum("")
  local uri = "game/user/info"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, "", nil, target)
end

--[[
function onGetUserInfo(data)
  --print("onGetUserInfo", data)
  local res = cjson.decode(data)
  if res==nil then return;end
  print(res.ret)
  if res.ret==0 then
    UserData.userinfo = cjson.decode(data)  
    Player.reload()
  else
    print("onGetUserInfo", res.ret) 
  end
  TimeManager.deltaTime = res.serverTime - os.time()
  
  --DailyRewardScene:getNode()
  local equip=HeroData:create(1)
  local sc = CCScene:create()
  --sc:addChild(equip:createTip())
  --curNode = ZhuangBeiScene.getNode()
  --sc:addChild(curNode.node)
  --CCDirector:sharedDirector():runWithScene(MainScene.getScene())
  CCDirector:sharedDirector():runWithScene(SelectNameScene.getScene())
  --CCDirector:sharedDirector():runWithScene(BeginScene.getScene())
  local textedit = CCEditBox:create(CCSizeMake(286, 73), "dailyquest_bk4.png", "test")
  textedit:setPosition(ccp(480, 320))
  textedit:setInputFlag(0)
  MainScene.scene:addChild(textedit)
  --CCDirector:sharedDirector():runWithScene(ShopScene.getScene())
  --CCDirector:sharedDirector():runWithScene(DailyRewardScene:getScene())
  --CCDirector:sharedDirector():runWithScene(ShouXunScene:getScene())
  --CCDirector:sharedDirector():runWithScene(ZBQHLayer:getScene())
  --CCDirector:sharedDirector():runWithScene(ZhuangBeiLayer3.getScene())
  --CCDirector:sharedDirector():runWithScene(sc)
  --CCDirector:sharedDirector():runWithScene(ZhanDouScene.getScene())
  --CCDirector:sharedDirector():runWithScene(XunLianYingScene.getScene())
  --CCDirector:sharedDirector():runWithScene(RenWuScene.getScene())
  --CCDirector:sharedDirector():runWithScene(JLRMLayer.getScene())
  --CCDirector:sharedDirector():runWithScene(RenWuDailyScene.getScene())
  --CCDirector:sharedDirector():runWithScene(YuanZhenScene.getScene())
  --CCDirector:sharedDirector():runWithScene(JLPYLayer.getScene())
  --CCDirector:sharedDirector():runWithScene(KeXueYuanScene.getScene())
  --CCDirector:sharedDirector():runWithScene(ZhuangBeiScene:getScene())
  --CCDirector:sharedDirector():runWithScene(FriendScene:getScene())
  
  --LoadScene:showLoadingAction() 
  --local res = cjson.decode(data)
  --for k,v in pairs(res) do
  --  print(k,v)
  --end 
  --print("onGetUserInfo",os.time(),res.serverTime,os.time()-res.serverTime)
end]]

NetworkRequest.test = function(callback, target)
  local url = "baidu.com"
  CCHttpClient:request(url, callback, "", target)
end

NetworkRequest.chooseHead = function(hid, name, gender, callback, target)
  local postdata = string.format('{"id":%d, "name":"%s", "gender":%d, "fiter":true}', hid, name, gender)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/user/headpic"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.upgradeBuilding = function(bid, callback, target)
  --bid=1234
  local postdata = string.format('{"bid":%d}', bid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/building/upgrade2"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
  --print(string.format(urlTpl, uri, checksum))
  --print(postdata)
end
--[[
function onUpgradeBuilding(data)
  local res = cjson.decode(data)
  NetworkRequest.syncData(res)
  if res.ret==0 then
    showMessage("升级成功", ccc3(0,255,0))
  else
    showMessage(res.msg, ccc3(255,255,0))
  end
end
]]

NetworkRequest.shouShui = function(callback, target)
  local postdata = '{"bid":1001}'
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/building/harvest2"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.revolt = function(revoltType, callback, target)
  local postdata = '{"useCoin":false,"sweetheart":false}'
  if revoltType==1 then
    postdata = '{"useCoin":true,"sweetheart":false}'
  elseif revoltType==2 then
    postdata = '{"useCoin":false,"sweetheart":true}'
  end 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/battle/revolt"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[
function onShouShui(data)
  print("onShouShui", data)
  local res = cjson.decode(data)
  NetworkRequest.syncData(res)
  if res.ret==0 then
    showMessage(string.format("cash:%d", res.data.gainCash), ccc3(0,255,0))
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end]]

NetworkRequest.getBattlePVE = function(strongholdid, checkpointid, callback, target)
  local postdata = string.format('{"strongholdId":%d,"checkpointId":%d,"npc_id":%d,"fill":true}', strongholdid, checkpointid, checkpointid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/battle/checkpoint"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
  --CCHttpClient:request(string.format(urlTpl, uri, checksum), "onGetBattlePVE", postdata)
  print(string.format(urlTpl, uri, checksum))
  print(postdata)
end
function onGetBattlePVE(data)
  print("onAssignSoldier", data)
  local res = cjson.decode(data)
  NetworkRequest.syncData(res)
  if res.ret~=0 then
    showMessage(res.msg, ccc3(255,255,0))
  elseif res.success==true then 
    --ZhanDouScene.setEvalStar(res.data.evaluate)
    --local msg = string.format("战斗胜利 exp:%d cash:%d",res.data.gainXp,res.data.gainCash)
    --showMessage(msg, ccc3(0,255,0))
    NetworkRequest.syncData(res)
    --ZhanDouScene.showWinWnd(res.data.gainXp,res.data.gainCash,res.data.evaluate)
    ZhanDouScene.showZhanDouView(data)
  else
    showMessage("战斗失败", ccc3(255,0,0))
  end
end

NetworkRequest.assignSoldier = function(level, callback, target)
  local postdata = string.format('{"contractId":%d}', level)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/building/product2"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[function onAssignSoldier(data)
  --print("onAssignSoldier", data)
  local res = cjson.decode(data)
  if res.ret==0 then
    NetworkRequest.syncData(res)
    showMessage(string.format("兵力增加%d", res.data.gainSoldiers), ccc3(0,255,0))
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end]]
NetworkRequest.giveUpQuest = function(id, callback, target)
  local postdata = string.format('{"qid":%d}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/giveUp"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.completeQuest = function(id, callback, target)
  local postdata = string.format('{"qid":%d}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/complete"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[
function onCompleteQuest(data)
  print("onAssignSoldier", data)
  local res = cjson.decode(data)
  if res.ret==0 then
    NetworkRequest.syncData(res)
    showMessage(string.format("任务完成 xp:%d cash:%d", res.data.xpReward, res.data.cashReward), ccc3(0,255,0))
    UserData.userinfo.curQuests = res.curQuests
    RenWuScene.acceptNextRenWu()  
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]

NetworkRequest.acceptQuest = function(id, callback, target, index)
  local postdata = ""
  if index==nil then
    postdata = string.format('{"qid":%d}', id)
  else
    postdata = string.format('{"qid":%d, "index":%d}', id, index)
  end
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/accept"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[
function onAcceptQuest(data)
  --print("onAssignSoldier", data)
  local res = cjson.decode(data)
  NetworkRequest.syncData(res)
  if res.ret==0 and res.data.result==true then
    showMessage("接受到新任务", ccc3(0,255,0))
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]

NetworkRequest.takeOff = function(heroid, equipIndex, action, target)
  local postdata = string.format('{"gid":%d, "ueid":%d}', heroid, equipIndex)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/takeOff"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), action, postdata, target)
end
--[[
function onTakeOff(data)
  print("onTakeOff", data)
  local res = cjson.decode(data)
  if res.ret==0 and res.data.result==true then
    --showMessage("接受到新任务", ccc3(0,255,0))
    NetworkRequest.syncData(res)
    ZhuangBeiLayer3.showEquip()
    ZhuangBeiLayer3.showEquipInTable()
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]
NetworkRequest.useItem = function(position, action, target)
  local postdata = string.format('{"pos":%d}', position)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/bag/useItem"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), action, postdata, target)
end
NetworkRequest.equip = function(heroid, equipIndex, action, target)
  local postdata = string.format('{"gid":%d, "ueid":%d}', heroid, equipIndex)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/equip"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), action, postdata, target)
end
--[[
function onEquip(data)
  print("onEquip", data)
  local res = cjson.decode(data)
  if res.ret==0 and res.data.result==true then
    --showMessage("接受到新任务", ccc3(0,255,0))
    NetworkRequest.syncData(res)
    ZhuangBeiLayer3.showEquip()
    ZhuangBeiLayer3.showEquipInTable()
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]

NetworkRequest.batchSell = function(pos, action, target)
  local postdata = string.format('{"sellArray":[{"pos":%d,"num":1}]}', pos)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/bag/batchSell"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), action, postdata, target)
end
NetworkRequest.buyItem = function(itemId, count, action, target)
  local postdata = string.format('{"itemId":%d, "num":%d}', itemId, count)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/bag/buyItem"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), action, postdata, target)
end

--[[
function onBatchSell(data)
  print("onEquip", data)
  local res = cjson.decode(data)
  if res.ret==0 and res.data.result==true then
    --showMessage("接受到新任务", ccc3(0,255,0))
    NetworkRequest.syncData(res)
    showMessage(string.format("cash:%d", res.data.sellCash), ccc3(0,255,0))
    ZhuangBeiLayer3.showEquipInTable()
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]
NetworkRequest.equipStrengthen = function(eindex, callback, target)
  local postdata = string.format('{"clearUp":false,"ueid":%d, "useCoin":false}', eindex)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/strengthen"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[
function onEquipStrengthen(data)
  print("onEquipStrengthen", data)
  local res = cjson.decode(data)
  if res.ret==0 and res.data.result==true then
    --showMessage("接受到新任务", ccc3(0,255,0))
    NetworkRequest.syncData(res)
    showMessage("强化成功", ccc3(0,255,0))
    --ZhuangBeiLayer3.showEquipInTable()
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end]]

NetworkRequest.upTech= function(tid, callback, target)
  local postdata = string.format('{"tid":%d}', tid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/upTech"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--[[
function onUpTech(data)
  print("onUpTech", data)
  local res = cjson.decode(data)
  if res.ret==0 and res.data.result==true then
    --showMessage("接受到新任务", ccc3(0,255,0))
    NetworkRequest.syncData(res)
    showMessage("升级成功", ccc3(0,255,0))
    --ZhuangBeiLayer3.showEquipInTable()
  else
    showMessage(res.msg, ccc3(255,0,0))
  end
end
]]
--http://app18894.qzoneapp.com/game/general/embattle?queryId=qid6&postKey=aabbccdd&check=JGJnSNN6UOTvAHqbWNQVH3jZnrcbNT9I-1364577983268-163&openkey=BC6B9302592F68EFFD34411D162DE651&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=e662521f9462908afa0feb440ad9f839&onlysign=
--{"tid":9,"formation":[2,0,0,0,91,136,0,0,1,0]}
NetworkRequest.changeZhenXing = function(zxid, zx, callback, target)
  local tmp = cjson.encode(zx)
  for k,v in pairs(zx) do print(k,v) end
  local postdata = string.format('{"tid":%d, "formation":%s}', zxid, tmp)
  print("NetworkRequest.changZhenXing", postdata)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/embattle"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.jingJiChang = function(callback, target)
  local checksum = NetworkRequest.makeChecksum("{}")
  local uri = "game/newAthletics/login"
  print("NetworkRequest.jingJiChang", urlTpl, uri, checksum)
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, "{}", target)
end
NetworkRequest.getJingJiChangBattle = function(uid, rate, callback, target)
  local postdata = string.format('{"targetId":%d,"rating":%d}', uid, rate)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/newAthletics/fight"
  print("NetworkRequest.getJingJiChangBattle", urlTpl, uri, checksum)
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.addFightTimes = function(callback, target)
  local checksum = NetworkRequest.makeChecksum("{}")
  local uri = "/game/newAthletics/addFightTimes"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, "{}", target)
end
--http://app18894.qzoneapp.com/game/newAthletics/seeTop20?queryId=qid6&postKey=aabbccdd&check=2HdLgiVs56NxgJX,LNZqdVyarjUi4642-1366987664312-52&openkey=56384CC4766B9159D2D46E6641FB5BA6&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=87420fa07caa221975a7951681b08aed&onlysign=
NetworkRequest.getJingJiChangRank = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/newAthletics/seeTop20"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/newAthletics/gainReward?queryId=qid8&postKey=aabbccdd&check=oOj5r9IrzwsnQdXI1b9alSgpg3bqejVv-1366988084236-96&openkey=56384CC4766B9159D2D46E6641FB5BA6&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=87420fa07caa221975a7951681b08aed&onlysign=
NetworkRequest.getJingJiChangReward = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/newAthletics/gainReward"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/newAthletics/clearCD?queryId=qid16&postKey=aabbccdd&check=gzmlbslJiO7dN4JZllEyE3JFZA6CO0ol-1366989559231-27&openkey=56384CC4766B9159D2D46E6641FB5BA6&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=87420fa07caa221975a7951681b08aed&onlysign=
NetworkRequest.clearJingJiChangCD = function(timereel, callback, target)
  local postdata = string.format('{"timereel":%s}', timereel) 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/newAthletics/clearCD"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
  --CCHttpClient:request("http://www.baidu.com", callback, postdata, target)
end

--function onjingJiChang(data)
--  print("onjingJiChang", data)
--end

NetworkRequest.qiYongZhenXing = function(zxid, callback, target)
  local postdata = string.format('{"tid":%d}', zxid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/defaultFormation"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/conquer/flush?queryId=qid8&postKey=aabbccdd&check=eE9pUdc85eS6g1CZT14F70htgmf74wRV-1365783940581-98&openkey=5EBB7161F0D0EB002D9E80AB557058CC&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=2c9a49b441c76f3d0db034432a6f2072&onlysign=
--http://app18894.qzoneapp.com/game/conquer/battle?queryId=qid7&postKey=aabbccdd&check=rKOIov13sJIqhD,1IR2INe4lK7wyBYx2-1365779631175-76&openkey=5EBB7161F0D0EB002D9E80AB557058CC&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=2c9a49b441c76f3d0db034432a6f2072&onlysign=
NetworkRequest.getYuanZhengBattle = function(cid, callback, target)
  local postdata = string.format('{"conquerId":%d}', cid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/conquer/battle"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.conquerBuy = function(id, callback, target)
  local postdata = string.format('{"goodsId":%d}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/conquer/buy"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.seeTopN = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/conquer/seeTopN"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.refreshYuanZheng = function(cid, paytype, callback, target)
  local postdata = ""
  if paytype=="coin" then
    postdata = string.format('{"useCoin":true,"useItem":false,"stageId":%d}', cid)
  elseif paytype=="yuanzhengling" then
    postdata = string.format('{"useCoin":false,"useItem":true,"stageId":%d}', cid)
  else
    postdata = string.format('{"useCoin":false,"useItem":false,"stageId":%d}', cid)
  end
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/conquer/flush"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end



NetworkRequest.autoFlushBounty = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/autoFlushBounty"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.flushBounty = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/flushBounty"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.flushDaily = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/quest/flush"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end



--http://app18894.qzoneapp.com/game/general/recruitRefresh?queryId=qid5&postKey=aabbccdd&check=GpTV.GAjpxkIc0Cjv8RSYjLmFPpAXYoW-1366040698604-214&openkey=B3B2E52DF86B5C18675644A982807D91&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d6f66875c50d66fd26da56ff35fe99ab&onlysign=
NetworkRequest.shouluGeneral = function(gid, callback, target)
  local postdata = string.format('{"gid":%d}', gid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/recruitRefresh"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/general/recruitGeneral?queryId=qid7&postKey=aabbccdd&check=qbdyNyzmeG,JsGApiPlrKCe5op,5DiHr-1366045477427-222&openkey=B3B2E52DF86B5C18675644A982807D91&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d6f66875c50d66fd26da56ff35fe99ab&onlysign=
NetworkRequest.zhaomuGeneral = function(gid, callback, target)
  local postdata = string.format('{"gid":%d}', gid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/recruitGeneral"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/general/fireGeneral?queryId=qid8&postKey=aabbccdd&check=jYB2zYTKmQNK.XDHlYrd,JM05W6D18l,-1366045614507-44&openkey=B3B2E52DF86B5C18675644A982807D91&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d6f66875c50d66fd26da56ff35fe99ab&onlysign=
NetworkRequest.xiayeGeneral = function(gid, callback, target)
  local postdata = string.format('{"gid":%d}', gid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/fireGeneral"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/general/expel?queryId=qid9&postKey=aabbccdd&check=ubAhaXAuOqWm8uEK2y0IwNS5QKF1Bt,r-1366045698595-130&openkey=B3B2E52DF86B5C18675644A982807D91&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d6f66875c50d66fd26da56ff35fe99ab&onlysign=
NetworkRequest.quzhuGeneral = function(gid, callback, target)
  local postdata = string.format('{"gid":%d}', gid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/expel"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/general/refresh?queryId=qid12&postKey=aabbccdd&check=qut,qI7rldnZpabVjffaxhO6oZeRaIyD-1366046778092-33&openkey=B3B2E52DF86B5C18675644A982807D91&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d6f66875c50d66fd26da56ff35fe99ab&onlysign=
--{"expireTime":1366651599,"costCoin":1,"id":3}
NetworkRequest.refreshGeneral = function(id, callback, target)
  local postdata = string.format('{"expireTime":%d,"costCoin":1,"id":%d}', os.time(), id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/refresh"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.resetAndRefreshGeneral = function(id, cost, callback, target)
  local postdata = string.format('{"expire":0,"id":%d,"costCoin":%d}', id, cost)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/general/resetAndRefresh"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.usePill = function(gid, count, callback, target)
  local postdata = string.format('{"gid":%d,"num":%d}', gid, count)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/general/usePill"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.hechengItem = function(stoneId, drugId, callback, target)
  local postdata = string.format('{"stoneId":%d,"num":1,"drugId":%d}', stoneId, drugId)
  print(postdata)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/upStone"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.upLevelEquip = function(stoneId, eqid, callback, target)
  local postdata = string.format('{"stoneId":%d,"useCoin":false,"ueid":%d}', stoneId, eqid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/upLevelEquip"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.upQualityEquip = function(stoneId, eqid, callback, target)
  local postdata = string.format('{"stoneId":%d,"useCoin":false,"ueid":%d}', stoneId, eqid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/upQualityEquip"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end


NetworkRequest.trainGeneral1 = function(gid, callback, target)
  local postdata = string.format('{"gid":%d}', gid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/fosterExploit"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.saveTrainGeneral = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/saveFoster"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.cancelTrainGeneral = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/cancelFoster"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

--http://app18894.qzoneapp.com/game/building/accelerate2?queryId=qid7&postKey=aabbccdd&check=kwDm,aNeg0lxFz4ui7sKcByszA6XCMkz-1366637683945-194&openkey=E71EA8DAC50B07BB0B1A8B483BEB814D&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=3336caba84c9823eedb3830461cc6043&onlysign=
--{"type":"Upgrading","bid":1004,"timereel":true}
--http://app18894.qzoneapp.com/game/general/resetTime?queryId=qid10&postKey=aabbccdd&check=KJI.GR2FNZI5jkmZ3UGYeu3jyVfsBxI6-1366638165305-162&openkey=E71EA8DAC50B07BB0B1A8B483BEB814D&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=3336caba84c9823eedb3830461cc6043&onlysign=
--{"timereel":true}
NetworkRequest.accelerate = function(t, bid, timereel, callback, target)
  local postdata = string.format('{"type":"%s", "bid":%d, "timereel":%s}', t, bid, timereel)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/building/accelerate2"
  print("NetworkRequest.accelerate", postdata)
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.resetTime = function(timereel, callback, target)
  local postdata = string.format('{"timereel":%s}', timereel)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/general/resetTime"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.clearCD = function(timereel, callback, target)
  local postdata = string.format('{"timereel":%s}', timereel)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/newAthletics/clearCD"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end




--http://app18894.qzoneapp.com/game/user/randomConquer?queryId=qid10&postKey=aabbccdd&check=DiIJb2sVzFXRF4rEhNzXg7Oh7dVyeL.K-1366901757637-80&openkey=6EEE4E276A3398EBE44E9C80EA6340AD&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=3a7943133ddaf40283c995d7b6611710&onlysign=
NetworkRequest.randomConquer = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/user/randomConquer"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/battle/occupy?queryId=qid12&postKey=aabbccdd&check=PQXUcE85uO.HlRaFUQm8M,Y,I0E5Tp6p-1366902875370-31&openkey=6EEE4E276A3398EBE44E9C80EA6340AD&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=3a7943133ddaf40283c995d7b6611710&onlysign=
NetworkRequest.occupy = function(id, callback, target)
  local postdata = string.format('{"fill":false,"enemyId":"%d"}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/battle/occupy"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/battle/retreat?queryId=qid14&postKey=aabbccdd&check=cKssZX7ZoBbh8fREOeq1BzyGP8wb6OSn-1366907410430-1&openkey=6EEE4E276A3398EBE44E9C80EA6340AD&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=3a7943133ddaf40283c995d7b6611710&onlysign=
NetworkRequest.retreat = function(id, callback, target)
  local postdata = string.format('{"enemyId":"%d"}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/battle/retreat"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.gainTribute = function(id, callback, target)
  local postdata = string.format('{"enemyId":"%d"}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/battle/gainTribute"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end




--http://app18894.qzoneapp.com/game/medal/decorate?queryId=qid5&postKey=aabbccdd&check=PrMJjz0n1.Sflm6C3j9d3tNoykGgVFve-1367075007646-129&openkey=EEBCD2DB0B4FB7C16419223D0ACB73E2&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=4a511fbe1579d207bfc5dda65c98e349&onlysign=
NetworkRequest.decorate = function(id, callback, target)
  local postdata = string.format('{"npc":%d}', id)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/decorate"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/pickUp?queryId=qid7&postKey=aabbccdd&check=HVzqpLezCTeQmFeol4KSwYGDeksFW59V-1367075180469-15&openkey=EEBCD2DB0B4FB7C16419223D0ACB73E2&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=4a511fbe1579d207bfc5dda65c98e349&onlysign=
NetworkRequest.pickUp = function(index, callback, target)
  local postdata = string.format('{"combine":false,"udid":%d}', index)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/pickUp"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/sold?queryId=qid10&postKey=aabbccdd&check=nW0jPdrRSVKpAhAcK5M20Z.X7T.x0Vj,-1367075360728-28&openkey=EEBCD2DB0B4FB7C16419223D0ACB73E2&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=4a511fbe1579d207bfc5dda65c98e349&onlysign=
NetworkRequest.sold = function(index, callback, target)
  local postdata = string.format('{"udid":%d}', index)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/sold"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/use?queryId=qid11&postKey=aabbccdd&check=e3nMTkYp2Q.UPmzyUXS5QUEIEMVl3mpM-1367075510953-41&openkey=EEBCD2DB0B4FB7C16419223D0ACB73E2&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=4a511fbe1579d207bfc5dda65c98e349&onlysign=
NetworkRequest.use = function(udid, gid, pos, callback, target)
  local postdata = string.format('{"udid":%d,"gid":%d,"pos":%d}', udid, gid, pos)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/use"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/move?queryId=qid12&postKey=aabbccdd&check=kYrgGe2x4fquClyibm8bdRYSadMePisS-1367075679795-66&openkey=EEBCD2DB0B4FB7C16419223D0ACB73E2&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=4a511fbe1579d207bfc5dda65c98e349&onlysign=
NetworkRequest.move = function(udid, pos, callback, target)
  local postdata = string.format('{"pos":%d,"udid":%d}', pos, udid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/move"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--{"guest":54,"master":53}
NetworkRequest.combine = function(master, guest, callback, target)
  local postdata = string.format('{"master":%d,"guest":%d}', master, guest)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/combine"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/pickUpAll?queryId=qid6&postKey=aabbccdd&check=FZpFczSBPg36owYV39JsY,qWKIkCayz,-1367333235780-199&openkey=69E08D3790DF6A950200010BD43A4E13&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d7f08f45a015c68e07361ba274567ec2&onlysign=
--{"combine":false}
NetworkRequest.pickUpAll = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/pickUpAll"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
--http://app18894.qzoneapp.com/game/medal/soldAll?queryId=qid5&postKey=aabbccdd&check=KHbWGe9QgAof,,fdZqfx,4V156LHgaej-1367333228221-220&openkey=69E08D3790DF6A950200010BD43A4E13&openid=0000000000000000000000005B168614&pf=pengyou&pfkey=d7f08f45a015c68e07361ba274567ec2&onlysign=
--{}
NetworkRequest.soldAll = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/soldAll"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.combineAll = function(callback, target)
  local postdata = string.format('{}')
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/medal/combineAll"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end




--/game/user/gainGiftBagRandom
NetworkRequest.gainGiftBagRandom = function(callback, target)
  local postdata = string.format('{}', master, guest)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/gainGiftBagRandom"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.getFriendList = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/finfo"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.findFriend = function(fid, callback, target)
  local postdata = string.format('{"fid":%s}', fid)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/searchFriend"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.viewFriends = function(callback, target)
  local postdata = '{}'
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "game/invitation/viewFriends"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.inviteFriends = function(uids, callback, target)
  local tmp = cjson.encode(uids)
  local postdata = string.format('{"invitees":%s}', tmp)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/invitation/inviteFriends"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.viewInvitationFriends = function(callback, target)
  local postdata = '{}'
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/invitation/viewInvitation"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.handleInvitation = function(id, flag, callback, target)
  local postdata = string.format('{"id":%d,"accept":%s}', id, flag)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/invitation/handleInvitation"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end


NetworkRequest.getGoodsMap = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/cayuan/phone/getGoodsMap"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end


NetworkRequest.bagOpen = function(useCoin, space, callback, target)
  local postdata = string.format('{"useCoin":%s, "space":%d}', useCoin, space)
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/bag/open"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end


--泡温泉
NetworkRequest.initExPower = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/initExPower"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.initExchange = function(callback, target)
  local postdata = "{}" 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/initExchange"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end

NetworkRequest.exchangePower = function(coin, power, callback, target)
  local postdata = string.format('{"energy":%d, "coin":%d}', power, coin) 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/exchangePower"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
NetworkRequest.exchangeCash = function(coin, cash, callback, target)
  local postdata = string.format('{"cash":%d, "coin":%d}', cash, coin) 
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/game/user/exchangeCash"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end


NetworkRequest.shops = function(callback, target)
  local postdata = "{}"
  local checksum = NetworkRequest.makeChecksum(postdata)
  local uri = "/cayuan/phone/shops"
  CCHttpClient:request(string.format(urlTpl, uri, checksum), callback, postdata, target)
end
